package cn.bird.tabledrive;

import lombok.Builder;
import lombok.Getter;

import java.util.function.BooleanSupplier;
import java.util.function.Supplier;

@Getter
public class TableDriveBean<T> {
    /**
     * 条件部分
     */
    protected BooleanSupplier booleanCondition;
    /**
     * 结果部分
     */
    protected Supplier<T> resultSupplier;
    /**
     * 存储当前的链工具
     */
    protected BooleanDriveUtil.BooleanDriveBuilder<T> booleanDriveBuilder;

    /**
     * 组装结果
     */
    public BooleanDriveUtil.BooleanDriveBuilder<T> result(T t){
        this.resultSupplier = () -> t;
        booleanDriveBuilder.tableDriveBeans.add(this);
        return booleanDriveBuilder;
    }

    /**
     * 组装结果
     */
    public BooleanDriveUtil.BooleanDriveBuilder<T> result(Supplier<T> resultSupplier){
        this.resultSupplier = resultSupplier;
        booleanDriveBuilder.tableDriveBeans.add(this);
        return booleanDriveBuilder;
    }

    protected TableDriveBean(BooleanSupplier booleanCondition, Supplier<T> resultSupplier) {
        this.booleanCondition = booleanCondition;
        this.resultSupplier = resultSupplier;
    }

    protected TableDriveBean(BooleanSupplier booleanCondition, BooleanDriveUtil.BooleanDriveBuilder<T> booleanDriveBuilder) {
        this.booleanCondition = booleanCondition;
        this.booleanDriveBuilder = booleanDriveBuilder;
    }

}
